//
//  TipImageView.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/7/3.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "TipImageView.h"

static NSString *rotationAnimationKey = @"rotationAnimationKey";

@implementation TipImageView


- (instancetype)init{
    
    if (self = [super init]) {
        //self.backgroundColor = [UIColor redColor];
        self.image = [UIImage imageNamed:@"check_listicon_loading"];
        
    }
    return self;
}

- (void)startLoading{
    
    CABasicAnimation* rotationAnimation =
    [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0];
    rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
    rotationAnimation.duration = 1.0f;
    rotationAnimation.repeatCount = INFINITY;
    CAMediaTimingFunction *defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    rotationAnimation.timingFunction = defaultCurve;
     rotationAnimation.removedOnCompletion = NO;
    [self.layer addAnimation:rotationAnimation forKey:rotationAnimationKey];
}

- (void)stopLoadIsFail:(BOOL)isFail{
    [self.layer removeAllAnimations];
    if (isFail) {
        
        self.image = [UIImage imageNamed:@"check_listicon_wrong"];
    }else{
        
        self.image = [UIImage imageNamed:@"check_listicon_right"];
    }
    
}

@end
